package com.jd.sunny.java;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Description:
 * @author:sunlin
 * @since:2012-11-28 18:39
 * @version:1.0.0
 */
public class Employee extends Person implements Cloneable,Serializable {

    private String company;
    private int salary;
    private Date entryTime;
    private Cat cat;

    /**
     * object equals method
     * son class has own equals meaning, must use getClass() to check
     * @param object
     * @return
     */
    public boolean equals(Object object){
        if(this == object){
            return true;
        }
        if(object==null){
            return false;
        }
        if(getClass()!=object.getClass()){
            return false;
        }
        com.jd.sunny.java.Employee employee = (com.jd.sunny.java.Employee)object;
        return this.company.equals(employee.getCompany()) && this.salary == employee.getSalary() && this.getName().equals(employee.getName()) && this.getSex().equals(employee.getSex());
    }

    public String getCompany() {
        return company;
    }

    public void setCompany(String company) {
        this.company = company;
    }

    public int getSalary() {
        return salary;
    }

    public void setSalary(int salary) {
        this.salary = salary;
    }

    public Date getEntryTime() {
        return entryTime;
    }

    public void setEntryTime(Date entryTime) {
        this.entryTime = entryTime;
    }

    public Cat getCat() {
        return cat;
    }

    public void setCat(Cat cat) {
        this.cat = cat;
    }

    /**
     * must use public because if the class isn't in the same package,it can't use protected method
     * in default situation
     * set the object new object doesn't influence,modify the object property has influence
     */

    @Override
    public Employee clone() {
        try {
            return (Employee)super.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * override toString
     * @return
     */
    public String toString(){
        return getClass().getName() + "[name=" + super.getName() + ",sex=" + super.getSex() + ",company=" + this.getCompany() + ",salary=" + this.getSalary() +"," + "entryTime=" +  new SimpleDateFormat("yyyy-MM-dd HH:ss:mm").format(entryTime)  +  "]";
    }

}
